﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Entity;
using XZL.GM.Dal;

public partial class Admin_User_UserList : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindUserList();
        }
    }


    private void BindUserList()
    {
        int? count = 0;
        int type = Convert.ToInt32(ddlType.SelectedValue);
        //上级ID为空
        divCondition.Visible = true;
        gridList.DataSource = UserInfoBiz.GetUserList(txtNickName.Text.Trim(), txtMobilePhone.Text.Trim(), type, netPager.CurrentPageIndex, netPager.PageSize, ref count);
        gridList.DataBind();
        netPager.RecordCount = count.Value;
        lblWarn.Text = "会员数量：" + count.Value;
    }


    /// <summary>
    /// 点击 编辑
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridList.EditIndex = e.NewEditIndex;
        BindUserList();
    }

    /// <summary>
    /// 点击取消
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        
        gridList.EditIndex = -1;
        BindUserList();
    }

    //点击 更新
    protected void gridList_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string userID = "";
        string realName;

        try
        {
            userID=gridList.DataKeys[e.RowIndex].Values[0].ToString();
        }
        catch(Exception ex)
        { 
        
        }

        try
        {
            realName = ((TextBox)gridList.Rows[e.RowIndex].FindControl("txtRealName")).Text.Trim();
         // realName.Length < 9;            
        }
        catch(Exception ex)
        {
            lblWarn.Text = "";
            return;
        }

        bool b = UserInfoBiz.UpdateRealName(userID, realName);
        if (b)
        {
            lblWarn.Text = "备注更新成功！";
            gridList.EditIndex = -1;
            BindUserList();
        }

    }




    /// <summary>
    /// 分页控件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void netPager_PageChanged(object sender, EventArgs e)
    {
        BindUserList();
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        BindUserList();
        netPager.CurrentPageIndex = 1;
    }


    /// <summary>
    /// 删除（更改状态）
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       
        string userID = gridList.DataKeys[e.RowIndex].Value.ToString();
        Proc_UserInfo_SelectUserInfoResult user = UserInfoBiz.GetUserInfo(userID);

        int s=0;
        if (user.Status == -1)
        {
            s = 1;
        }
        else if (user.Status == 1)
        {
            s = -1;
        }

        gridList.Visible = UserInfoBiz.ChangeStatus(userID,s);
        BindUserList();
    }
}